package com.github.rxyor.example.transaction.goods.controller;

import com.github.rxyor.example.transaction.goods.business.GoodsBusiness;
import com.github.rxyor.example.transaction.goods.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2019-05-29 Wed 14:56:00
 * @since 1.0.0
 */
@Slf4j
@Api(value = "goods")
@RestController
@AllArgsConstructor
@RequestMapping("/goods")
public class GoodsController {

    private final GoodsBusiness goodsBusiness;
    private final GoodsService goodsService;

    @ApiOperation(value = "脏读", httpMethod = "POST")
    @PostMapping("/test/read_uncommitted")
    @ResponseBody
    public Object readUncommitted() {
        goodsBusiness.risePriceByReadUncommitted(1L, new BigDecimal("1"));
        return null;
    }

    @ApiOperation(value = "Aop事务", httpMethod = "POST")
    @PostMapping("/test/aop/transaction")
    @ResponseBody
    public Object aopTransaction() {
        goodsService.risePriceById(1L, new BigDecimal("1"));
        return null;
    }
}
